//
//  AppDelegate.swift
//  CHSimpleUI
//
//  Created by cyptt on 2022/5/31.
//

import UIKit
import IQKeyboardManagerSwift
@main
class AppDelegate: UIResponder, UIApplicationDelegate {


    enum BarCode1{
        
        case testCase(name:Int)
    }

    enum Barcode {
        case upc(Int, Int, Int, Int)
        case qrCode(String)
    }
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        let result:String = UIDevice.current.identifierForVendor!.uuidString
        print(result)
        
        CHCrashNote.shareInstance().configExceptionHandler()
        CHCrashHandler.setup { [weak self] (stackTrace,completion) in
            completion()
        }
        IQKeyboardManager.shared.enable = true
      
//        self.setdata()
//
//        self.image()
//
//        self.urlstr()
//        self.rang()
        
        self.swiftTest()
        
//        let threeTimesTable =  TimesTable(multiplier: 3, test: 5)
//        let threeTimesTable =  TimesTable()
//        print(threeTimesTable)
//        print(threeTimesTable[4])
//
//        print(threeTimesTable["name"])
//
//        let task:URLSessionDataTask = URLSessionDataTask()
//        task.resume()
//        task.cancel()
        let queue = DispatchQueue.init(label: "ch.queue.com.<#name#>",qos: DispatchQoS.default)
        queue.async {
            print(Thread.current)
        }
        
        let name = "addd12344444fdjfhdhf"
//        print(name.sub(fromString: "234", iscontain: true))
        
        print(name.sub(toString: "1234", iscontain: false))
        let tabbar = CHTabBarController.init(navClass: UINavigationController.self)
        self.window?.rootViewController = tabbar
       
        return true
    }
    
    

  
    struct TimesTable{
        let multiplier: Int
        let test:Int
        subscript(index:Int)->Int{
            return multiplier * index
        }
      
        subscript(name:String)->String{
            return name
        }
    }
    func testCase(name:Int){
        
        print(name)
    }
    
    func swiftTest(){
       var barC = BarCode1.testCase(name: 3)
    
        
        var productBarcode = Barcode.upc(8, 85909, 51226, 3)
        print(productBarcode)
        
//        let names = ["zs","lisi","wangw"]
//        for name in names[1...] {
//            print(name)
//        }
        
//        let range = 0...5
//       let isSuccess =  range.contains(3)
//        print(isSuccess)
        
        return
        let dollarSign = "\u{23}"
        print(dollarSign)
        
        let dollarSign1 = "\u{24}"
        print(dollarSign1)
        
        let sign2 = "\""
        print(sign2)
        
        let sign3 = "\u{1F496}"
        print(sign3)
        
        let wiseWords = "\"Imagination is more important than knowledge\" - Einstein"
        print(wiseWords)
        
        let sign4 = "\""
        print(sign4)
        
        for character in "Dog!🐶" {
            print(character)
        }
        
        print("\(dollarSign)")
        print(#"Write an interpolated string in Swift using \#(dollarSign)."#)
        
    
        let testname111 = "test0010001niddddd"
        
        let isTest0:Bool = testname111.hasPrefix("est001")
        print(isTest0)
        
        
        let isTest:Bool = testname111.hasPrefix("test001")
        print(isTest)
        
   
        let isTest2:Bool = testname111.hasSuffix("dddd")
        print(isTest2)
        
        for scalar in testname111.unicodeScalars{
            print("\(scalar)")
        }
        
        let arr0:[Any] = []
        print(arr0.isEmpty)
        
        
        let arr2:[Any] = ["1","a","d","f","b"]
        
        for (index,value) in arr2.enumerated() {
            print("Item \(index + 1): \(value)")
        }
        
        let favSets:Set<String> = ["rock","jack","tom","hop"]
        
        for itemName in favSets{
        
            print(itemName)
        }
        
        for itemName in favSets.sorted(){
            print(itemName)
        }
        
        let oddDigits: Set = [1, 3, 5, 7, 9]
        let evenDigits: Set = [0, 2, 4, 6, 8]
        let singleDigitPrimeNumbers: Set = [2, 3, 5, 7]
    
        
        print(oddDigits.union(evenDigits))
        print(oddDigits.union(evenDigits).sorted())
        
        print(oddDigits.subtracting(singleDigitPrimeNumbers))
        print(oddDigits.symmetricDifference(singleDigitPrimeNumbers))
        
        let bounds = returnTwo()
        
        print(bounds.min)
        print(bounds.two)
        
        var someInt = 3
        var anotherInt = 107
   
        swapTwoInts(&someInt, &anotherInt)
      
      
    }
    
    func swapTwoInts(_ a: inout Int, _ b: inout Int) {
        print(a)
        let temporaryA = a
        a = b
        b = temporaryA
    }
    
    func chooseStepFunction(backward: Bool) -> (Int) -> Int {
        func stepForward(input: Int) -> Int {
            return input + 1
            
        }
        func stepBackward(input: Int) -> Int {
            return input - 1
            
        }
        return backward ? stepBackward : stepForward
    }
    func returnTwo() -> (min:Int ,two:Int){
        
        return(3,4)
    }
    func rang(){
        let rang:Range = 2 ..< 4
        print("rang",rang)
        
        print(rang.startIndex)
        print(rang.index(of: 3))
        print(rang[3])
        
 
//        let rang2:Range<String> = 2 ..< 4
        
       
        var name:String = "dfdkjdfdjs"
        
        let stringIndex:String.Index = name.index(name.startIndex, offsetBy: 3)
        
        let endIndex:String.Index = name.endIndex
        

        print(name[stringIndex..<endIndex])
        

        let rang2:Range<String.Index> = stringIndex ..< endIndex

        
        
//        let sub:String? = name.replacingCharacters(in: rang2, with: "3333")
     
    
       
      
        
//        print(sub)
        
        var desensitName:String = "abcdefg"
        print("=======",desensitName.desensit(from: 0, to: 7, replacing: "***"))
        print(desensitName.sub(from: 0, to: 7))
    }
    
    func urlstr(){
        let name:String = "nndmddfdf中国"
        name.data(using: .ascii)
        let urlName:String = CHUrlCode.urlencode(name)
        print(urlName)
        
        print(CHUrlCode.urlDecode(urlName))
    }

    func image(){
        let image:UIImage? = UIImage.init(named: "arrow_down_icon")
        
        print(image)
        
        
      

    }
    
    func setdata(){
        let name:String = "adcv1234我的";
        
        
        
        let data:Data? =  name.data(using: .utf8)
        
     
        
        print("data",data);
        
    
        let dataStr:String? = String.init(data: data!, encoding: .unicode)
        print("dataStr",dataStr)
        
        
        let encodeData:Data? = data?.base64EncodedData()
        print("encodeData",encodeData)
        
        let encodeDataStr:String? = String.init(data: encodeData!, encoding: .utf8)
        print("encodeDataStr",encodeDataStr)
      
     
        print(CHBase64.base64Decoding(base64String: encodeDataStr!))
        
//        let decodedString:String? =  encodeData!.base64EncodedData(options: <#T##Data.Base64EncodingOptions#>)
        
        
        
        
        let decodedData = NSData(base64Encoded: encodeDataStr!, options: NSData.Base64DecodingOptions.init(rawValue: 0))
        
        let decodeStrig0 = String.init(data: decodedData! as Data, encoding: .utf8)
        print(decodeStrig0)
        
        let decodedString1 = NSString(data: decodedData! as Data, encoding: String.Encoding.utf8.rawValue)! as String
        
        print("decodedString1",decodedString1)
        
        
        
        let decodedString2 = NSString(data: encodeData! as Data, encoding: String.Encoding.utf8.rawValue)! as String
        print("decodedString2",decodedString2)
    }


}

